import unittest
import socket

class Computer():
    '''Computer class'''

    unique_number=0

    def __init__(self, name, ip=None):
        '''Initialize the computer'''
        self.name=name
        self.number=Computer.unique_number
        Computer.unique_number+=1
        if ip == None:
            self.ip=self._find_ip(self.name)

    def _find_ip(self, name):
        '''Translate a host name to IPv4 address format.'''
        if name is not None:
            return socket.gethostbyname(name)

    def get_ip_info(self):
        '''
        Translate a host name to IPv4 address format, extended interface.
        Return a triple (hostname, aliaslist, ipaddrlist) where hostname is the primary host
        name responding to the given ip_address, aliaslist is a (possibly empty) list of
        alternative host names for the same address, and ipaddrlist is a list of IPv4
        addresses for the same interface on the same host (often but not always a
        single address).
        '''
        if self.name is not None:
            return socket.gethostbyname_ex(self.name)


class ComputerTest(unittest.TestCase):
    def setUp(self):
        self.c1=Computer("localhost")
        self.c2=Computer("www.klm.nl")

    def test_find_ip(self):
        self.assertEqual(self.c1.ip , "127.0.0.1")
        self.assertEqual(self.c2.ip , "171.21.122.79")

    def testget_ip_info(self):
        self.assertEqual(self.c1.get_ip_info()[0],'HP6730b')

if __name__=='__main__':
    unittest.main()
